//
//  DVBarDelegate.m
//  FitnessVideo
//
//  Created by tikeios_001 on 2023/5/5.
//

#import "CLBarDelegate.h"
@interface CLBarDelegate() {
    NSArray *hiddenControllers;
}
@end

@implementation CLBarDelegate
- (instancetype)init {
    if (self = [super init]) {
        hiddenControllers = @[@"SoketListVC"];
    }
    return self;
}

+ (CLBarDelegate *)share {
    static CLBarDelegate *delegate;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        delegate = [[CLBarDelegate alloc] init];
    });
    return delegate;
}

#pragma mark -UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    BOOL navigationBarHidden = NO;
    NSString *viewControllerName = NSStringFromClass([viewController class]);
    if ([hiddenControllers containsObject:viewControllerName]) {
        navigationBarHidden = YES;
    }
    if (navigationBarHidden) {
        if (!navigationController.isNavigationBarHidden) {
            [navigationController setNavigationBarHidden:YES animated:YES];
        }
    } else {
        if (navigationController.isNavigationBarHidden) {
            [navigationController setNavigationBarHidden:NO animated:YES];
        }
    }
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if ([navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
        navigationController.interactivePopGestureRecognizer.enabled = YES;
    }
    
    if (navigationController.viewControllers.count == 1) {
        navigationController.interactivePopGestureRecognizer.enabled = NO;
        navigationController.interactivePopGestureRecognizer.delegate = nil;
    }
}
@end
